// +----------------------------------------------------------------------
// | CmsWing [ 美业管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 psi All rights reserved.
// +----------------------------------------------------------------------
// | Author: huang <2374266244@qq.com>
// +----------------------------------------------------------------------
'use strict';

export default class extends think.Controller {
  /**
   * index action
   * @return {Promise} []
   */
  // 获取分店员工数据
  async getStaffListAction() {
    const filter = this.get();
    const where = {};
    where['u.shopid'] = filter.shopid;
    if (filter.search) {
      where['u.name'] = ['like', '%' + filter.search + '%'];
    }
    const list = await this.model('or_app_user')
      .alias('u')
      .field('u.*, p.name as zname, ps.name as pname, count(a.userid) as yynum')
      .join('think_or_position p on u.zhichengid = p.id')
      .join('think_or_position ps on u.positionid = ps.id')
      .join('think_or_appointment a on u.id=a.userid')
      .where(where)
      .group('u.id')
      .select();
    return this.json(list);
  }
}
